home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / gas / doc / as.info-1 < prev    next >
Encoding:
GNU Info File  |  1996-07-15  |  48.4 KB  |  1,344 lines

  1. This is Info file as.info, produced by Makeinfo-1.55 from the input
  2. file ./as.texinfo.
  3.  
  4. START-INFO-DIR-ENTRY
  5. * As: (as).                     The GNU assembler.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the GNU Assembler "as".
  9.  
  10.    Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation,
  11. Inc.
  12.  
  13.    Permission is granted to make and distribute verbatim copies of this
  14. manual provided the copyright notice and this permission notice are
  15. preserved on all copies.
  16.  
  17.    Permission is granted to copy and distribute modified versions of
  18. this manual under the conditions for verbatim copying, provided that
  19. the entire resulting derived work is distributed under the terms of a
  20. permission notice identical to this one.
  21.  
  22.    Permission is granted to copy and distribute translations of this
  23. manual into another language, under the above conditions for modified
  24. versions.
  25.  
  26. 
  27. File: as.info,  Node: Top,  Next: Overview,  Prev: (DIR),  Up: (DIR)
  28.  
  29. Using as
  30. ********
  31.  
  32.    This file is a user guide to the GNU assembler `as'.
  33.  
  34. * Menu:
  35.  
  36. * Overview::                    Overview
  37. * Invoking::                    Command-Line Options
  38. * Syntax::                      Syntax
  39. * Sections::                    Sections and Relocation
  40. * Symbols::                     Symbols
  41. * Expressions::                 Expressions
  42. * Pseudo Ops::                  Assembler Directives
  43. * Machine Dependencies::        Machine Dependent Features
  44. * Acknowledgements::            Who Did What
  45. * Index::                       Index
  46.  
  47. 
  48. File: as.info,  Node: Overview,  Next: Invoking,  Prev: Top,  Up: Top
  49.  
  50. Overview
  51. ********
  52.  
  53.    Here is a brief summary of how to invoke `as'.  For details, *note
  54. Comand-Line Options: Invoking..
  55.  
  56.      as [ -a[dhlns][=file] ] [ -D ]  [ --defsym SYM=VAL ]
  57.       [ -f ] [ --help ] [ -I DIR ] [ -J ] [ -K ] [ -L ]
  58.       [ -o OBJFILE ] [ -R ] [ --statistics ] [ -v ] [ -version ]
  59.       [ --version ] [ -W ] [ -w ] [ -x ] [ -Z ]
  60.       [ -Av6 | -Av7 | -Av8 | -Asparclite | -Av9 | -Av9a ]
  61.       [ -xarch=v8plus | -xarch=v8plusa ] [ -bump ]
  62.       [ -ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC ]
  63.       [ -b ] [ -no-relax ]
  64.       [ -l ] [ -m68000 | -m68010 | -m68020 | ... ]
  65.       [ -nocpp ] [ -EL ] [ -EB ] [ -G NUM ] [ -mcpu=CPU ]
  66.       [ -mips1 ] [ -mips2 ] [ -mips3 ] [ -m4650 ] [ -no-m4650 ]
  67.       [ --trap ] [ --break ]
  68.       [ --emulation=NAME ]
  69.       [ -- | FILES ... ]
  70.  
  71. `-a[dhlns]'
  72.      Turn on listings, in any of a variety of ways:
  73.  
  74.     `-ad'
  75.           omit debugging directives
  76.  
  77.     `-ah'
  78.           include high-level source
  79.  
  80.     `-al'
  81.           include assembly
  82.  
  83.     `-an'
  84.           omit forms processing
  85.  
  86.     `-as'
  87.           include symbols
  88.  
  89.     `=file'
  90.           set the name of the listing file
  91.  
  92.      You may combine these options; for example, use `-aln' for assembly
  93.      listing without forms processing.  The `=file' option, if used,
  94.      must be the last one.  By itself, `-a' defaults to `-ahls'--that
  95.      is, all listings turned on.
  96.  
  97. `-D'
  98.      Ignored.  This option is accepted for script compatibility with
  99.      calls to other assemblers.
  100.  
  101. `--defsym SYM=VALUE'
  102.      Define the symbol SYM to be VALUE before assembling the input file.
  103.      vALUE must be an integer constant.  As in C, a leading `0x'
  104.      indicates a hexadecimal value, and a leading `0' indicates an
  105.      octal value.
  106.  
  107. `-f'
  108.      "fast"--skip whitespace and comment preprocessing (assume source is
  109.      compiler output).
  110.  
  111. `--help'
  112.      Print a summary of the command line options and exit.
  113.  
  114. `-I DIR'
  115.      Add directory DIR to the search list for `.include' directives.
  116.  
  117. `-J'
  118.      Don't warn about signed overflow.
  119.  
  120. `-K'
  121.      Issue warnings when difference tables altered for long
  122.      displacements.
  123.  
  124. `-L'
  125.      Keep (in the symbol table) local symbols, starting with `L'.
  126.  
  127. `-o OBJFILE'
  128.      Name the object-file output from `as' OBJFILE.
  129.  
  130. `-R'
  131.      Fold the data section into the text section.
  132.  
  133. `--statistics'
  134.      Print the maximum space (in bytes) and total time (in seconds)
  135.      used by assembly.
  136.  
  137. `-v'
  138. `-version'
  139.      Print the `as' version.
  140.  
  141. `--version'
  142.      Print the `as' version and exit.
  143.  
  144. `-W'
  145.      Suppress warning messages.
  146.  
  147. `-w'
  148.      Ignored.
  149.  
  150. `-x'
  151.      Ignored.
  152.  
  153. `-Z'
  154.      Generate an object file even after errors.
  155.  
  156. `-- | FILES ...'
  157.      Standard input, or source files to assemble.
  158.  
  159.    The following options are available when as is configured for the
  160. Intel 80960 processor.
  161.  
  162. `-ACA | -ACA_A | -ACB | -ACC | -AKA | -AKB | -AKC | -AMC'
  163.      Specify which variant of the 960 architecture is the target.
  164.  
  165. `-b'
  166.      Add code to collect statistics about branches taken.
  167.  
  168. `-no-relax'
  169.      Do not alter compare-and-branch instructions for long
  170.      displacements; error if necessary.
  171.  
  172.    The following options are available when as is configured for the
  173. Motorola 68000 series.
  174.  
  175. `-l'
  176.      Shorten references to undefined symbols, to one word instead of
  177.      two.
  178.  
  179. `-m68000 | -m68008 | -m68010 | -m68020 | -m68030 | -m68040'
  180. `| -m68302 | -m68331 | -m68332 | -m68333 | -m68340 | -mcpu32'
  181.      Specify what processor in the 68000 family is the target.  The
  182.      default is normally the 68020, but this can be changed at
  183.      configuration time.
  184.  
  185. `-m68881 | -m68882 | -mno-68881 | -mno-68882'
  186.      The target machine does (or does not) have a floating-point
  187.      coprocessor.  The default is to assume a coprocessor for 68020,
  188.      68030, and cpu32.  Although the basic 68000 is not compatible with
  189.      the 68881, a combination of the two can be specified, since it's
  190.      possible to do emulation of the coprocessor instructions with the
  191.      main processor.
  192.  
  193. `-m68851 | -mno-68851'
  194.      The target machine does (or does not) have a memory-management
  195.      unit coprocessor.  The default is to assume an MMU for 68020 and
  196.      up.
  197.  
  198.    The following options are available when `as' is configured for the
  199. SPARC architecture:
  200.  
  201. `-Av6 | -Av7 | -Av8 | -Asparclite | -Av9 | -Av9a'
  202.      Explicitly select a variant of the SPARC architecture.
  203.  
  204. `-xarch=v8plus | -xarch=v8plusa'
  205.      For compatibility with the Solaris v9 assembler.  These options are
  206.      equivalent to -Av9 and -Av9a, respectively.
  207.  
  208. `-bump'
  209.      Warn when the assembler switches to another architecture.
  210.  
  211.    The following options are available when as is configured for a MIPS
  212. processor.
  213.  
  214. `-G NUM'
  215.      This option sets the largest size of an object that can be
  216.      referenced implicitly with the `gp' register.  It is only accepted
  217.      for targets that use ECOFF format, such as a DECstation running
  218.      Ultrix.  The default value is 8.
  219.  
  220. `-EB'
  221.      Generate "big endian" format output.
  222.  
  223. `-EL'
  224.      Generate "little endian" format output.
  225.  
  226. `-mips1'
  227. `-mips2'
  228. `-mips3'
  229.      Generate code for a particular MIPS Instruction Set Architecture
  230.      level.  `-mips1' corresponds to the R2000 and R3000 processors,
  231.      `-mips2' to the R6000 processor, and `-mips3' to the R4000
  232.      processor.
  233.  
  234. `-m4650'
  235. `-no-m4650'
  236.      Generate code for the MIPS R4650 chip.  This tells the assembler
  237.      to accept the `mad' and `madu' instruction, and to not schedule
  238.      `nop' instructions around accesses to the `HI' and `LO' registers.
  239.      `-no-m4650' turns off this option.
  240.  
  241. `-mcpu=CPU'
  242.      Generate code for a particular MIPS cpu.  This has little effect
  243.      on the assembler, but it is passed by `gcc'.
  244.  
  245. `--emulation=NAME'
  246.      This option causes `as' to emulated `as' configured for some other
  247.      target, in all respects, including output format (choosing between
  248.      ELF and ECOFF only), handling of pseudo-opcodes which may generate
  249.      debugging information or store symbol table information, and
  250.      default endianness.  The available configuration names are:
  251.      `mipsecoff', `mipself', `mipslecoff', `mipsbecoff', `mipslelf',
  252.      `mipsbelf'.  The first two do not alter the default endianness
  253.      from that of the primary target for which the assembler was
  254.      configured; the others change the default to little- or big-endian
  255.      as indicated by the `b' or `l' in the name.  Using `-EB' or `-EL'
  256.      will override the endianness selection in any case.
  257.  
  258.      This option is currently supported only when the primary target
  259.      `as' is configured for is a MIPS ELF or ECOFF target.
  260.      Furthermore, the primary target or others specified with
  261.      `--enable-targets=...' at configuration time must include support
  262.      for the other format, if both are to be available.  For example,
  263.      the Irix 5 configuration includes support for both.
  264.  
  265.      Eventually, this option will support more configurations, with more
  266.      fine-grained control over the assembler's behavior, and will be
  267.      supported for more processors.
  268.  
  269. `-nocpp'
  270.      `as' ignores this option.  It is accepted for compatibility with
  271.      the native tools.
  272.  
  273. `--trap'
  274. `--no-trap'
  275. `--break'
  276. `--no-break'
  277.      Control how to deal with multiplication overflow and division by
  278.      zero.  `--trap' or `--no-break' (which are synonyms) take a trap
  279.      exception (and only work for Instruction Set Architecture level 2
  280.      and higher); `--break' or `--no-trap' (also synonyms, and the
  281.      default) take a break exception.
  282.  
  283. * Menu:
  284.  
  285. * Manual::                      Structure of this Manual
  286. * GNU Assembler::               as, the GNU Assembler
  287. * Object Formats::              Object File Formats
  288. * Command Line::                Command Line
  289. * Input Files::                 Input Files
  290. * Object::                      Output (Object) File
  291. * Errors::                      Error and Warning Messages
  292.  
  293. 
  294. File: as.info,  Node: Manual,  Next: GNU Assembler,  Up: Overview
  295.  
  296. Structure of this Manual
  297. ========================
  298.  
  299.    This manual is intended to describe what you need to know to use GNU
  300. `as'.  We cover the syntax expected in source files, including notation
  301. for symbols, constants, and expressions; the directives that `as'
  302. understands; and of course how to invoke `as'.
  303.  
  304.    This manual also describes some of the machine-dependent features of
  305. various flavors of the assembler.
  306.  
  307.    On the other hand, this manual is *not* intended as an introduction
  308. to programming in assembly language--let alone programming in general!
  309. In a similar vein, we make no attempt to introduce the machine
  310. architecture; we do *not* describe the instruction set, standard
  311. mnemonics, registers or addressing modes that are standard to a
  312. particular architecture.  You may want to consult the manufacturer's
  313. machine architecture manual for this information.
  314.  
  315. 
  316. File: as.info,  Node: GNU Assembler,  Next: Object Formats,  Prev: Manual,  Up: Overview
  317.  
  318. as, the GNU Assembler
  319. =====================
  320.  
  321.    GNU `as' is really a family of assemblers.  If you use (or have
  322. used) the GNU assembler on one architecture, you should find a fairly
  323. similar environment when you use it on another architecture.  Each
  324. version has much in common with the others, including object file
  325. formats, most assembler directives (often called "pseudo-ops") and
  326. assembler syntax.
  327.  
  328.    `as' is primarily intended to assemble the output of the GNU C
  329. compiler `gcc' for use by the linker `ld'.  Nevertheless, we've tried
  330. to make `as' assemble correctly everything that other assemblers for
  331. the same machine would assemble.  Any exceptions are documented
  332. explicitly (*note Machine Dependencies::.).  This doesn't mean `as'
  333. always uses the same syntax as another assembler for the same
  334. architecture; for example, we know of several incompatible versions of
  335. 680x0 assembly language syntax.
  336.  
  337.    Unlike older assemblers, `as' is designed to assemble a source
  338. program in one pass of the source file.  This has a subtle impact on the
  339. `.org' directive (*note `.org': Org.).
  340.  
  341. 
  342. File: as.info,  Node: Object Formats,  Next: Command Line,  Prev: GNU Assembler,  Up: Overview
  343.  
  344. Object File Formats
  345. ===================
  346.  
  347.    The GNU assembler can be configured to produce several alternative
  348. object file formats.  For the most part, this does not affect how you
  349. write assembly language programs; but directives for debugging symbols
  350. are typically different in different file formats.  *Note Symbol
  351. Attributes: Symbol Attributes.
  352.  
  353. 
  354. File: as.info,  Node: Command Line,  Next: Input Files,  Prev: Object Formats,  Up: Overview
  355.  
  356. Command Line
  357. ============
  358.  
  359.    After the program name `as', the command line may contain options
  360. and file names.  Options may appear in any order, and may be before,
  361. after, or between file names.  The order of file names is significant.
  362.  
  363.    `--' (two hyphens) by itself names the standard input file
  364. explicitly, as one of the files for `as' to assemble.
  365.  
  366.    Except for `--' any command line argument that begins with a hyphen
  367. (`-') is an option.  Each option changes the behavior of `as'.  No
  368. option changes the way another option works.  An option is a `-'
  369. followed by one or more letters; the case of the letter is important.
  370. All options are optional.
  371.  
  372.    Some options expect exactly one file name to follow them.  The file
  373. name may either immediately follow the option's letter (compatible with
  374. older assemblers) or it may be the next command argument (GNU
  375. standard).  These two command lines are equivalent:
  376.  
  377.      as -o my-object-file.o mumble.s
  378.      as -omy-object-file.o mumble.s
  379.  
  380. 
  381. File: as.info,  Node: Input Files,  Next: Object,  Prev: Command Line,  Up: Overview
  382.  
  383. Input Files
  384. ===========
  385.  
  386.    We use the phrase "source program", abbreviated "source", to
  387. describe the program input to one run of `as'.  The program may be in
  388. one or more files; how the source is partitioned into files doesn't
  389. change the meaning of the source.
  390.  
  391.    The source program is a concatenation of the text in all the files,
  392. in the order specified.
  393.  
  394.    Each time you run `as' it assembles exactly one source program.  The
  395. source program is made up of one or more files.  (The standard input is
  396. also a file.)
  397.  
  398.    You give `as' a command line that has zero or more input file names.
  399. The input files are read (from left file name to right).  A command
  400. line argument (in any position) that has no special meaning is taken to
  401. be an input file name.
  402.  
  403.    If you give `as' no file names it attempts to read one input file
  404. from the `as' standard input, which is normally your terminal.  You may
  405. have to type ctl-D to tell `as' there is no more program to assemble.
  406.  
  407.    Use `--' if you need to explicitly name the standard input file in
  408. your command line.
  409.  
  410.    If the source is empty, `as' produces a small, empty object file.
  411.  
  412. Filenames and Line-numbers
  413. --------------------------
  414.  
  415.    There are two ways of locating a line in the input file (or files)
  416. and either may be used in reporting error messages.  One way refers to
  417. a line number in a physical file; the other refers to a line number in a
  418. "logical" file.  *Note Error and Warning Messages: Errors.
  419.  
  420.    "Physical files" are those files named in the command line given to
  421. `as'.
  422.  
  423.    "Logical files" are simply names declared explicitly by assembler
  424. directives; they bear no relation to physical files.  Logical file names
  425. help error messages reflect the original source file, when `as' source
  426. is itself synthesized from other files.  *Note `.app-file': App-File.
  427.  
  428. 
  429. File: as.info,  Node: Object,  Next: Errors,  Prev: Input Files,  Up: Overview
  430.  
  431. Output (Object) File
  432. ====================
  433.  
  434.    Every time you run `as' it produces an output file, which is your
  435. assembly language program translated into numbers.  This file is the
  436. object file.  Its default name is `a.out', or `b.out' when `as' is
  437. configured for the Intel 80960.  You can give it another name by using
  438. the `-o' option.  Conventionally, object file names end with `.o'.  The
  439. default name is used for historical reasons: older assemblers were
  440. capable of assembling self-contained programs directly into a runnable
  441. program.  (For some formats, this isn't currently possible, but it can
  442. be done for the `a.out' format.)
  443.  
  444.    The object file is meant for input to the linker `ld'.  It contains
  445. assembled program code, information to help `ld' integrate the
  446. assembled program into a runnable file, and (optionally) symbolic
  447. information for the debugger.
  448.  
  449. 
  450. File: as.info,  Node: Errors,  Prev: Object,  Up: Overview
  451.  
  452. Error and Warning Messages
  453. ==========================
  454.  
  455.    `as' may write warnings and error messages to the standard error
  456. file (usually your terminal).  This should not happen when  a compiler
  457. runs `as' automatically.  Warnings report an assumption made so that
  458. `as' could keep assembling a flawed program; errors report a grave
  459. problem that stops the assembly.
  460.  
  461.    Warning messages have the format
  462.  
  463.      file_name:NNN:Warning Message Text
  464.  
  465. (where NNN is a line number).  If a logical file name has been given
  466. (*note `.app-file': App-File.) it is used for the filename, otherwise
  467. the name of the current input file is used.  If a logical line number
  468. was given (*note `.line': Line.) then it is used to calculate the
  469. number printed, otherwise the actual line in the current source file is
  470. printed.  The message text is intended to be self explanatory (in the
  471. grand Unix tradition).
  472.  
  473.    Error messages have the format
  474.      file_name:NNN:FATAL:Error Message Text
  475.    The file name and line number are derived as for warning messages.
  476. The actual message text may be rather less explanatory because many of
  477. them aren't supposed to happen.
  478.  
  479. 
  480. File: as.info,  Node: Invoking,  Next: Syntax,  Prev: Overview,  Up: Top
  481.  
  482. Command-Line Options
  483. ********************
  484.  
  485.    This chapter describes command-line options available in *all*
  486. versions of the GNU assembler; *note Machine Dependencies::., for
  487. options specific to particular machine architectures.
  488.  
  489.    If you are invoking `as' via the GNU C compiler (version 2), you can
  490. use the `-Wa' option to pass arguments through to the assembler.  The
  491. assembler arguments must be separated from each other (and the `-Wa')
  492. by commas.  For example:
  493.  
  494.      gcc -c -g -O -Wa,-alh,-L file.c
  495.  
  496. emits a listing to standard output with high-level and assembly source.
  497.  
  498.    Usually you do not need to use this `-Wa' mechanism, since many
  499. compiler command-line options are automatically passed to the assembler
  500. by the compiler.  (You can call the GNU compiler driver with the `-v'
  501. option to see precisely what options it passes to each compilation
  502. pass, including the assembler.)
  503.  
  504. * Menu:
  505.  
  506. * a::             -a[dhlns] enable listings
  507. * D::             -D for compatibility
  508. * f::             -f to work faster
  509. * I::             -I for .include search path
  510.  
  511. * K::             -K for difference tables
  512.  
  513. * L::             -L to retain local labels
  514. * M::          -M or -mri to assemble in MRI compatibility mode
  515. * o::             -o to name the object file
  516. * R::             -R to join data and text sections
  517. * statistics::    -statistics to see statistics about assembly
  518. * v::             -v to announce version
  519. * W::             -W to suppress warnings
  520. * Z::             -Z to make object file even after errors
  521.  
  522. 
  523. File: as.info,  Node: a,  Next: D,  Up: Invoking
  524.  
  525. Enable Listings: `-a[dhlns]'
  526. ============================
  527.  
  528.    These options enable listing output from the assembler.  By itself,
  529. `-a' requests high-level, assembly, and symbols listing.  You can use
  530. other letters to select specific options for the list: `-ah' requests a
  531. high-level language listing, `-al' requests an output-program assembly
  532. listing, and `-as' requests a symbol table listing.  High-level
  533. listings require that a compiler debugging option like `-g' be used,
  534. and that assembly listings (`-al') be requested also.
  535.  
  536.    Use the `-ad' option to omit debugging directives from the listing.
  537.  
  538.    Once you have specified one of these options, you can further control
  539. listing output and its appearance using the directives `.list',
  540. `.nolist', `.psize', `.eject', `.title', and `.sbttl'.  The `-an'
  541. option turns off all forms processing.  If you do not request listing
  542. output with one of the `-a' options, the listing-control directives
  543. have no effect.
  544.  
  545.    The letters after `-a' may be combined into one option, *e.g.*,
  546. `-aln'.
  547.  
  548. 
  549. File: as.info,  Node: D,  Next: f,  Prev: a,  Up: Invoking
  550.  
  551. `-D'
  552. ====
  553.  
  554.    This option has no effect whatsoever, but it is accepted to make it
  555. more likely that scripts written for other assemblers also work with
  556. `as'.
  557.  
  558. 
  559. File: as.info,  Node: f,  Next: I,  Prev: D,  Up: Invoking
  560.  
  561. Work Faster: `-f'
  562. =================
  563.  
  564.    `-f' should only be used when assembling programs written by a
  565. (trusted) compiler.  `-f' stops the assembler from doing whitespace and
  566. comment preprocessing on the input file(s) before assembling them.
  567. *Note Preprocessing: Preprocessing.
  568.  
  569.      *Warning:* if you use `-f' when the files actually need to be
  570.      preprocessed (if they contain comments, for example), `as' does
  571.      not work correctly.
  572.  
  573. 
  574. File: as.info,  Node: I,  Next: K,  Prev: f,  Up: Invoking
  575.  
  576. `.include' search path: `-I' PATH
  577. =================================
  578.  
  579.    Use this option to add a PATH to the list of directories `as'
  580. searches for files specified in `.include' directives (*note
  581. `.include': Include.).  You may use `-I' as many times as necessary to
  582. include a variety of paths.  The current working directory is always
  583. searched first; after that, `as' searches any `-I' directories in the
  584. same order as they were specified (left to right) on the command line.
  585.  
  586. 
  587. File: as.info,  Node: K,  Next: L,  Prev: I,  Up: Invoking
  588.  
  589. Difference Tables: `-K'
  590. =======================
  591.  
  592.    `as' sometimes alters the code emitted for directives of the form
  593. `.word SYM1-SYM2'; *note `.word': Word..  You can use the `-K' option
  594. if you want a warning issued when this is done.
  595.  
  596. 
  597. File: as.info,  Node: L,  Next: M,  Prev: K,  Up: Invoking
  598.  
  599. Include Local Labels: `-L'
  600. ==========================
  601.  
  602.    Labels beginning with `L' (upper case only) are called "local
  603. labels". *Note Symbol Names::.  Normally you do not see such labels when
  604. debugging, because they are intended for the use of programs (like
  605. compilers) that compose assembler programs, not for your notice.
  606. Normally both `as' and `ld' discard such labels, so you do not normally
  607. debug with them.
  608.  
  609.    This option tells `as' to retain those `L...' symbols in the object
  610. file.  Usually if you do this you also tell the linker `ld' to preserve
  611. symbols whose names begin with `L'.
  612.  
  613.    By default, a local label is any label beginning with `L', but each
  614. target is allowed to redefine the local label prefix.  On the HPPA
  615. local labels begin with `L$'.
  616.  
  617. 
  618. File: as.info,  Node: M,  Next: o,  Prev: L,  Up: Invoking
  619.  
  620. Assemble in MRI Compatibility Mode: `-M'
  621. ========================================
  622.  
  623.    The `-M' or `--mri' option selects MRI compatibility mode.  This
  624. changes the syntax and pseudo-op handling of `as' to make it compatible
  625. with the `ASM68K' or the `ASM960' (depending upon the configured
  626. target) assembler from Microtec Research.  The exact nature of the MRI
  627. syntax will not be documented here; see the MRI manuals for more
  628. information.  The purpose of this option is to permit assembling
  629. existing MRI assembler code using `as'.
  630.  
  631.    The MRI compatibility is not complete.  Certain operations of the
  632. MRI assembler depend upon its object file format, and can not be
  633. supported using other object file formats.  Supporting these would
  634. require enhancing each object file format individually.  These are:
  635.  
  636.    * global symbols in common section
  637.  
  638.      The m68k MRI assembler supports common sections which are merged
  639.      by the linker.  Other object file formats do not support this.
  640.      `as' handles common sections by treating them as a single common
  641.      symbol.  It permits local symbols to be defined within a common
  642.      section, but it can not support global symbols, since it has no
  643.      way to describe them.
  644.  
  645.    * complex relocations
  646.  
  647.      The MRI assemblers support relocations against a negated section
  648.      address, and relocations which combine the start addresses of two
  649.      or more sections.  These are not support by other object file
  650.      formats.
  651.  
  652.    * `END' pseudo-op specifying start address
  653.  
  654.      The MRI `END' pseudo-op permits the specification of a start
  655.      address.  This is not supported by other object file formats.  The
  656.      start address may instead be specified using the `-e' option to
  657.      the linker, or in a linker script.
  658.  
  659.    * `IDNT', `.ident' and `NAME' pseudo-ops
  660.  
  661.      The MRI `IDNT', `.ident' and `NAME' pseudo-ops assign a module
  662.      name to the output file.  This is not supported by other object
  663.      file formats.
  664.  
  665.    * `ORG' pseudo-op
  666.  
  667.      The m68k MRI `ORG' pseudo-op begins an absolute section at a given
  668.      address.  This differs from the usual `as' `.org' pseudo-op, which
  669.      changes the location within the current section.  Absolute
  670.      sections are not supported by other object file formats.  The
  671.      address of a section may be assigned within a linker script.
  672.  
  673.    There are some other features of the MRI assembler which are not
  674. supported by `as', typically either because they are difficult or
  675. because they seem of little consequence.  Some of these may be
  676. supported in future releases.
  677.  
  678.    * EBCDIC strings
  679.  
  680.      EBCDIC strings are not supported.
  681.  
  682.    * packed binary coded decimal
  683.  
  684.      Packed binary coded decimal is not supported.  This means that the
  685.      `DC.P' and `DCB.P' pseudo-ops are not supported.
  686.  
  687.    * `FEQU' pseudo-op
  688.  
  689.      The m68k `FEQU' pseudo-op is not supported.
  690.  
  691.    * `NOOBJ' pseudo-op
  692.  
  693.      The m68k `NOOBJ' pseudo-op is not supported.
  694.  
  695.    * `OPT' branch control options
  696.  
  697.      The m68k `OPT' branch control options--`B', `BRS', `BRB', `BRL',
  698.      and `BRW'--are ignored.  `as' automatically relaxes all branches,
  699.      whether forward or backward, to an appropriate size, so these
  700.      options serve no purpose.
  701.  
  702.    * `OPT' list control options
  703.  
  704.      The following m68k `OPT' list control options are ignored: `C',
  705.      `CEX', `CL', `CRE', `E', `G', `I', `M', `MEX', `MC', `MD', `X'.
  706.  
  707.    * other `OPT' options
  708.  
  709.      The following m68k `OPT' options are ignored: `NEST', `O', `OLD',
  710.      `OP', `P', `PCO', `PCR', `PCS', `R'.
  711.  
  712.    * `OPT' `D' option is default
  713.  
  714.      The m68k `OPT' `D' option is the default, unlike the MRI assembler.
  715.      `OPT NOD' may be used to turn it off.
  716.  
  717.    * `XREF' pseudo-op.
  718.  
  719.      The m68k `XREF' pseudo-op is ignored.
  720.  
  721.    * `.debug' pseudo-op
  722.  
  723.      The i960 `.debug' pseudo-op is not supported.
  724.  
  725.    * `.extended' pseudo-op
  726.  
  727.      The i960 `.extended' pseudo-op is not supported.
  728.  
  729.    * `.list' pseudo-op.
  730.  
  731.      The various options of the i960 `.list' pseudo-op are not
  732.      supported.
  733.  
  734.    * `.optimize' pseudo-op
  735.  
  736.      The i960 `.optimize' pseudo-op is not supported.
  737.  
  738.    * `.output' pseudo-op
  739.  
  740.      The i960 `.output' pseudo-op is not supported.
  741.  
  742.    * `.setreal' pseudo-op
  743.  
  744.      The i960 `.setreal' pseudo-op is not supported.
  745.  
  746. 
  747. File: as.info,  Node: o,  Next: R,  Prev: M,  Up: Invoking
  748.  
  749. Name the Object File: `-o'
  750. ==========================
  751.  
  752.    There is always one object file output when you run `as'.  By
  753. default it has the name `a.out' (or `b.out', for Intel 960 targets
  754. only).  You use this option (which takes exactly one filename) to give
  755. the object file a different name.
  756.  
  757.    Whatever the object file is called, `as' overwrites any existing
  758. file of the same name.
  759.  
  760. 
  761. File: as.info,  Node: R,  Next: statistics,  Prev: o,  Up: Invoking
  762.  
  763. Join Data and Text Sections: `-R'
  764. =================================
  765.  
  766.    `-R' tells `as' to write the object file as if all data-section data
  767. lives in the text section.  This is only done at the very last moment:
  768. your binary data are the same, but data section parts are relocated
  769. differently.  The data section part of your object file is zero bytes
  770. long because all its bytes are appended to the text section.  (*Note
  771. Sections and Relocation: Sections.)
  772.  
  773.    When you specify `-R' it would be possible to generate shorter
  774. address displacements (because we do not have to cross between text and
  775. data section).  We refrain from doing this simply for compatibility with
  776. older versions of `as'.  In future, `-R' may work this way.
  777.  
  778.    When `as' is configured for COFF output, this option is only useful
  779. if you use sections named `.text' and `.data'.
  780.  
  781.    `-R' is not supported for any of the HPPA targets.  Using `-R'
  782. generates a warning from `as'.
  783.  
  784. 
  785. File: as.info,  Node: statistics,  Next: v,  Prev: R,  Up: Invoking
  786.  
  787. Display Assembly Statistics: `--statistics'
  788. ===========================================
  789.  
  790.    Use `--statistics' to display two statistics about the resources
  791. used by `as': the maximum amount of space allocated during the assembly
  792. (in bytes), and the total execution time taken for the assembly (in CPU
  793. seconds).
  794.  
  795. 
  796. File: as.info,  Node: v,  Next: W,  Prev: statistics,  Up: Invoking
  797.  
  798. Announce Version: `-v'
  799. ======================
  800.  
  801.    You can find out what version of as is running by including the
  802. option `-v' (which you can also spell as `-version') on the command
  803. line.
  804.  
  805. 
  806. File: as.info,  Node: W,  Next: Z,  Prev: v,  Up: Invoking
  807.  
  808. Suppress Warnings: `-W'
  809. =======================
  810.  
  811.    `as' should never give a warning or error message when assembling
  812. compiler output.  But programs written by people often cause `as' to
  813. give a warning that a particular assumption was made.  All such
  814. warnings are directed to the standard error file.  If you use this
  815. option, no warnings are issued.  This option only affects the warning
  816. messages: it does not change any particular of how `as' assembles your
  817. file.  Errors, which stop the assembly, are still reported.
  818.  
  819. 
  820. File: as.info,  Node: Z,  Prev: W,  Up: Invoking
  821.  
  822. Generate Object File in Spite of Errors: `-Z'
  823. =============================================
  824.  
  825.    After an error message, `as' normally produces no output.  If for
  826. some reason you are interested in object file output even after `as'
  827. gives an error message on your program, use the `-Z' option.  If there
  828. are any errors, `as' continues anyways, and writes an object file after
  829. a final warning message of the form `N errors, M warnings, generating
  830. bad object file.'
  831.  
  832. 
  833. File: as.info,  Node: Syntax,  Next: Sections,  Prev: Invoking,  Up: Top
  834.  
  835. Syntax
  836. ******
  837.  
  838.    This chapter describes the machine-independent syntax allowed in a
  839. source file.  `as' syntax is similar to what many other assemblers use;
  840. it is inspired by the BSD 4.2 assembler, except that `as' does not
  841. assemble Vax bit-fields.
  842.  
  843. * Menu:
  844.  
  845. * Preprocessing::              Preprocessing
  846. * Whitespace::                  Whitespace
  847. * Comments::                    Comments
  848. * Symbol Intro::                Symbols
  849. * Statements::                  Statements
  850. * Constants::                   Constants
  851.  
  852. 
  853. File: as.info,  Node: Preprocessing,  Next: Whitespace,  Up: Syntax
  854.  
  855. Preprocessing
  856. =============
  857.  
  858.    The `as' internal preprocessor:
  859.    * adjusts and removes extra whitespace.  It leaves one space or tab
  860.      before the keywords on a line, and turns any other whitespace on
  861.      the line into a single space.
  862.  
  863.    * removes all comments, replacing them with a single space, or an
  864.      appropriate number of newlines.
  865.  
  866.    * converts character constants into the appropriate numeric values.
  867.  
  868.    It does not do macro processing, include file handling, or anything
  869. else you may get from your C compiler's preprocessor.  You can do
  870. include file processing with the `.include' directive (*note
  871. `.include': Include.).  You can use the GNU C compiler driver to get
  872. other "CPP" style preprocessing, by giving the input file a `.S'
  873. suffix.  *Note Options Controlling the Kind of Output:
  874. (gcc.info)Overall Options.
  875.  
  876.    Excess whitespace, comments, and character constants cannot be used
  877. in the portions of the input text that are not preprocessed.
  878.  
  879.    If the first line of an input file is `#NO_APP' or if you use the
  880. `-f' option, whitespace and comments are not removed from the input
  881. file.  Within an input file, you can ask for whitespace and comment
  882. removal in specific portions of the by putting a line that says `#APP'
  883. before the text that may contain whitespace or comments, and putting a
  884. line that says `#NO_APP' after this text.  This feature is mainly
  885. intend to support `asm' statements in compilers whose output is
  886. otherwise free of comments and whitespace.
  887.  
  888. 
  889. File: as.info,  Node: Whitespace,  Next: Comments,  Prev: Preprocessing,  Up: Syntax
  890.  
  891. Whitespace
  892. ==========
  893.  
  894.    "Whitespace" is one or more blanks or tabs, in any order.
  895. Whitespace is used to separate symbols, and to make programs neater for
  896. people to read.  Unless within character constants (*note Character
  897. Constants: Characters.), any whitespace means the same as exactly one
  898. space.
  899.  
  900. 
  901. File: as.info,  Node: Comments,  Next: Symbol Intro,  Prev: Whitespace,  Up: Syntax
  902.  
  903. Comments
  904. ========
  905.  
  906.    There are two ways of rendering comments to `as'.  In both cases the
  907. comment is equivalent to one space.
  908.  
  909.    Anything from `/*' through the next `*/' is a comment.  This means
  910. you may not nest these comments.
  911.  
  912.      /*
  913.        The only way to include a newline ('\n') in a comment
  914.        is to use this sort of comment.
  915.      */
  916.      
  917.      /* This sort of comment does not nest. */
  918.  
  919.    Anything from the "line comment" character to the next newline is
  920. considered a comment and is ignored.  The line comment character is `;'
  921. for the AMD 29K family; `;' for the H8/300 family; `!' for the H8/500
  922. family; `;' for the HPPA; `#' on the i960; `!' for the Hitachi SH; `!'
  923. on the SPARC; `|' on the 680x0; `#' on the Vax; `!' for the Z8000; see
  924. *Note Machine Dependencies::.
  925.  
  926.    On some machines there are two different line comment characters.
  927. One character only begins a comment if it is the first non-whitespace
  928. character on a line, while the other always begins a comment.
  929.  
  930.    To be compatible with past assemblers, lines that begin with `#'
  931. have a special interpretation.  Following the `#' should be an absolute
  932. expression (*note Expressions::.): the logical line number of the *next*
  933. line.  Then a string (*note Strings: Strings.) is allowed: if present
  934. it is a new logical file name.  The rest of the line, if any, should be
  935. whitespace.
  936.  
  937.    If the first non-whitespace characters on the line are not numeric,
  938. the line is ignored.  (Just like a comment.)
  939.  
  940.                                # This is an ordinary comment.
  941.      # 42-6 "new_file_name"    # New logical file name
  942.                                # This is logical line # 36.
  943.    This feature is deprecated, and may disappear from future versions
  944. of `as'.
  945.  
  946. 
  947. File: as.info,  Node: Symbol Intro,  Next: Statements,  Prev: Comments,  Up: Syntax
  948.  
  949. Symbols
  950. =======
  951.  
  952.    A "symbol" is one or more characters chosen from the set of all
  953. letters (both upper and lower case), digits and the three characters
  954. `_.$'.  On most machines, you can also use `$' in symbol names;
  955. exceptions are noted in *Note Machine Dependencies::.  No symbol may
  956. begin with a digit.  Case is significant.  There is no length limit:
  957. all characters are significant.  Symbols are delimited by characters
  958. not in that set, or by the beginning of a file (since the source
  959. program must end with a newline, the end of a file is not a possible
  960. symbol delimiter).  *Note Symbols::.
  961.  
  962. 
  963. File: as.info,  Node: Statements,  Next: Constants,  Prev: Symbol Intro,  Up: Syntax
  964.  
  965. Statements
  966. ==========
  967.  
  968.    A "statement" ends at a newline character (`\n') or line separator
  969. character.  (The line separator is usually `;', unless this conflicts
  970. with the comment character; *note Machine Dependencies::..)  The
  971. newline or separator character is considered part of the preceding
  972. statement.  Newlines and separators within character constants are an
  973. exception: they do not end statements.
  974.  
  975.    It is an error to end any statement with end-of-file:  the last
  976. character of any input file should be a newline.
  977.  
  978.    You may write a statement on more than one line if you put a
  979. backslash (`\') immediately in front of any newlines within the
  980. statement.  When `as' reads a backslashed newline both characters are
  981. ignored.  You can even put backslashed newlines in the middle of symbol
  982. names without changing the meaning of your source program.
  983.  
  984.    An empty statement is allowed, and may include whitespace.  It is
  985. ignored.
  986.  
  987.    A statement begins with zero or more labels, optionally followed by a
  988. key symbol which determines what kind of statement it is.  The key
  989. symbol determines the syntax of the rest of the statement.  If the
  990. symbol begins with a dot `.' then the statement is an assembler
  991. directive: typically valid for any computer.  If the symbol begins with
  992. a letter the statement is an assembly language "instruction": it
  993. assembles into a machine language instruction.  Different versions of
  994. `as' for different computers recognize different instructions.  In
  995. fact, the same symbol may represent a different instruction in a
  996. different computer's assembly language.
  997.  
  998.    A label is a symbol immediately followed by a colon (`:').
  999. Whitespace before a label or after a colon is permitted, but you may not
  1000. have whitespace between a label's symbol and its colon. *Note Labels::.
  1001.  
  1002.    For HPPA targets, labels need not be immediately followed by a
  1003. colon, but the definition of a label must begin in column zero.  This
  1004. also implies that only one label may be defined on each line.
  1005.  
  1006.      label:     .directive    followed by something
  1007.      another_label:           # This is an empty statement.
  1008.                 instruction   operand_1, operand_2, ...
  1009.  
  1010. 
  1011. File: as.info,  Node: Constants,  Prev: Statements,  Up: Syntax
  1012.  
  1013. Constants
  1014. =========
  1015.  
  1016.    A constant is a number, written so that its value is known by
  1017. inspection, without knowing any context.  Like this:
  1018.      .byte  74, 0112, 092, 0x4A, 0X4a, 'J, '\J # All the same value.
  1019.      .ascii "Ring the bell\7"                  # A string constant.
  1020.      .octa  0x123456789abcdef0123456789ABCDEF0 # A bignum.
  1021.      .float 0f-314159265358979323846264338327\
  1022.      95028841971.693993751E-40                 # - pi, a flonum.
  1023.  
  1024. * Menu:
  1025.  
  1026. * Characters::                  Character Constants
  1027. * Numbers::                     Number Constants
  1028.  
  1029. 
  1030. File: as.info,  Node: Characters,  Next: Numbers,  Up: Constants
  1031.  
  1032. Character Constants
  1033. -------------------
  1034.  
  1035.    There are two kinds of character constants.  A "character" stands
  1036. for one character in one byte and its value may be used in numeric
  1037. expressions.  String constants (properly called string *literals*) are
  1038. potentially many bytes and their values may not be used in arithmetic
  1039. expressions.
  1040.  
  1041. * Menu:
  1042.  
  1043. * Strings::                     Strings
  1044. * Chars::                       Characters
  1045.  
  1046. 
  1047. File: as.info,  Node: Strings,  Next: Chars,  Up: Characters
  1048.  
  1049. Strings
  1050. .......
  1051.  
  1052.    A "string" is written between double-quotes.  It may contain
  1053. double-quotes or null characters.  The way to get special characters
  1054. into a string is to "escape" these characters: precede them with a
  1055. backslash `\' character.  For example `\\' represents one backslash:
  1056. the first `\' is an escape which tells `as' to interpret the second
  1057. character literally as a backslash (which prevents `as' from
  1058. recognizing the second `\' as an escape character).  The complete list
  1059. of escapes follows.
  1060.  
  1061. `\b'
  1062.      Mnemonic for backspace; for ASCII this is octal code 010.
  1063.  
  1064. `\f'
  1065.      Mnemonic for FormFeed; for ASCII this is octal code 014.
  1066.  
  1067. `\n'
  1068.      Mnemonic for newline; for ASCII this is octal code 012.
  1069.  
  1070. `\r'
  1071.      Mnemonic for carriage-Return; for ASCII this is octal code 015.
  1072.  
  1073. `\t'
  1074.      Mnemonic for horizontal Tab; for ASCII this is octal code 011.
  1075.  
  1076. `\ DIGIT DIGIT DIGIT'
  1077.      An octal character code.  The numeric code is 3 octal digits.  For
  1078.      compatibility with other Unix systems, 8 and 9 are accepted as
  1079.      digits: for example, `\008' has the value 010, and `\009' the
  1080.      value 011.
  1081.  
  1082. `\`x' HEX-DIGITS...'
  1083.      A hex character code.  All trailing hex digits are combined.
  1084.      Either upper or lower case `x' works.
  1085.  
  1086. `\\'
  1087.      Represents one `\' character.
  1088.  
  1089. `\"'
  1090.      Represents one `"' character.  Needed in strings to represent this
  1091.      character, because an unescaped `"' would end the string.
  1092.  
  1093. `\ ANYTHING-ELSE'
  1094.      Any other character when escaped by `\' gives a warning, but
  1095.      assembles as if the `\' was not present.  The idea is that if you
  1096.      used an escape sequence you clearly didn't want the literal
  1097.      interpretation of the following character.  However `as' has no
  1098.      other interpretation, so `as' knows it is giving you the wrong
  1099.      code and warns you of the fact.
  1100.  
  1101.    Which characters are escapable, and what those escapes represent,
  1102. varies widely among assemblers.  The current set is what we think the
  1103. BSD 4.2 assembler recognizes, and is a subset of what most C compilers
  1104. recognize.  If you are in doubt, do not use an escape sequence.
  1105.  
  1106. 
  1107. File: as.info,  Node: Chars,  Prev: Strings,  Up: Characters
  1108.  
  1109. Characters
  1110. ..........
  1111.  
  1112.    A single character may be written as a single quote immediately
  1113. followed by that character.  The same escapes apply to characters as to
  1114. strings.  So if you want to write the character backslash, you must
  1115. write `'\\' where the first `\' escapes the second `\'.  As you can
  1116. see, the quote is an acute accent, not a grave accent.  A newline
  1117. immediately following an acute accent is taken as a literal character
  1118. and does not count as the end of a statement.  The value of a character
  1119. constant in a numeric expression is the machine's byte-wide code for
  1120. that character.  `as' assumes your character code is ASCII: `'A' means
  1121. 65, `'B' means 66, and so on.
  1122.  
  1123. 
  1124. File: as.info,  Node: Numbers,  Prev: Characters,  Up: Constants
  1125.  
  1126. Number Constants
  1127. ----------------
  1128.  
  1129.    `as' distinguishes three kinds of numbers according to how they are
  1130. stored in the target machine.  *Integers* are numbers that would fit
  1131. into an `int' in the C language.  *Bignums* are integers, but they are
  1132. stored in more than 32 bits.  *Flonums* are floating point numbers,
  1133. described below.
  1134.  
  1135. * Menu:
  1136.  
  1137. * Integers::                    Integers
  1138. * Bignums::                     Bignums
  1139. * Flonums::                     Flonums
  1140.  
  1141. 
  1142. File: as.info,  Node: Integers,  Next: Bignums,  Up: Numbers
  1143.  
  1144. Integers
  1145. ........
  1146.  
  1147.    A binary integer is `0b' or `0B' followed by zero or more of the
  1148. binary digits `01'.
  1149.  
  1150.    An octal integer is `0' followed by zero or more of the octal digits
  1151. (`01234567').
  1152.  
  1153.    A decimal integer starts with a non-zero digit followed by zero or
  1154. more digits (`0123456789').
  1155.  
  1156.    A hexadecimal integer is `0x' or `0X' followed by one or more
  1157. hexadecimal digits chosen from `0123456789abcdefABCDEF'.
  1158.  
  1159.    Integers have the usual values.  To denote a negative integer, use
  1160. the prefix operator `-' discussed under expressions (*note Prefix
  1161. Operators: Prefix Ops.).
  1162.  
  1163. 
  1164. File: as.info,  Node: Bignums,  Next: Flonums,  Prev: Integers,  Up: Numbers
  1165.  
  1166. Bignums
  1167. .......
  1168.  
  1169.    A "bignum" has the same syntax and semantics as an integer except
  1170. that the number (or its negative) takes more than 32 bits to represent
  1171. in binary.  The distinction is made because in some places integers are
  1172. permitted while bignums are not.
  1173.  
  1174. 
  1175. File: as.info,  Node: Flonums,  Prev: Bignums,  Up: Numbers
  1176.  
  1177. Flonums
  1178. .......
  1179.  
  1180.    A "flonum" represents a floating point number.  The translation is
  1181. indirect: a decimal floating point number from the text is converted by
  1182. `as' to a generic binary floating point number of more than sufficient
  1183. precision.  This generic floating point number is converted to a
  1184. particular computer's floating point format (or formats) by a portion
  1185. of `as' specialized to that computer.
  1186.  
  1187.    A flonum is written by writing (in order)
  1188.    * The digit `0'.  (`0' is optional on the HPPA.)
  1189.  
  1190.    * A letter, to tell `as' the rest of the number is a flonum.  `e' is
  1191.      recommended.  Case is not important.
  1192.  
  1193.      On the H8/300, H8/500, Hitachi SH, and AMD 29K architectures, the
  1194.      letter must be one of the letters `DFPRSX' (in upper or lower
  1195.      case).
  1196.  
  1197.      On the Intel 960 architecture, the letter must be one of the
  1198.      letters `DFT' (in upper or lower case).
  1199.  
  1200.      On the HPPA architecture, the letter must be `E' (upper case only).
  1201.  
  1202.    * An optional sign: either `+' or `-'.
  1203.  
  1204.    * An optional "integer part": zero or more decimal digits.
  1205.  
  1206.    * An optional "fractional part": `.' followed by zero or more
  1207.      decimal digits.
  1208.  
  1209.    * An optional exponent, consisting of:
  1210.  
  1211.         * An `E' or `e'.
  1212.  
  1213.         * Optional sign: either `+' or `-'.
  1214.  
  1215.         * One or more decimal digits.
  1216.  
  1217.    At least one of the integer part or the fractional part must be
  1218. present.  The floating point number has the usual base-10 value.
  1219.  
  1220.    `as' does all processing using integers.  Flonums are computed
  1221. independently of any floating point hardware in the computer running
  1222. `as'.
  1223.  
  1224. 
  1225. File: as.info,  Node: Sections,  Next: Symbols,  Prev: Syntax,  Up: Top
  1226.  
  1227. Sections and Relocation
  1228. ***********************
  1229.  
  1230. * Menu:
  1231.  
  1232. * Secs Background::             Background
  1233. * Ld Sections::                 ld Sections
  1234. * As Sections::                 as Internal Sections
  1235. * Sub-Sections::                Sub-Sections
  1236. * bss::                         bss Section
  1237.  
  1238. 
  1239. File: as.info,  Node: Secs Background,  Next: Ld Sections,  Up: Sections
  1240.  
  1241. Background
  1242. ==========
  1243.  
  1244.    Roughly, a section is a range of addresses, with no gaps; all data
  1245. "in" those addresses is treated the same for some particular purpose.
  1246. For example there may be a "read only" section.
  1247.  
  1248.    The linker `ld' reads many object files (partial programs) and
  1249. combines their contents to form a runnable program.  When `as' emits an
  1250. object file, the partial program is assumed to start at address 0.
  1251. `ld' assigns the final addresses for the partial program, so that
  1252. different partial programs do not overlap.  This is actually an
  1253. oversimplification, but it suffices to explain how `as' uses sections.
  1254.  
  1255.    `ld' moves blocks of bytes of your program to their run-time
  1256. addresses.  These blocks slide to their run-time addresses as rigid
  1257. units; their length does not change and neither does the order of bytes
  1258. within them.  Such a rigid unit is called a *section*.  Assigning
  1259. run-time addresses to sections is called "relocation".  It includes the
  1260. task of adjusting mentions of object-file addresses so they refer to
  1261. the proper run-time addresses.  For the H8/300 and H8/500, and for the
  1262. Hitachi SH, `as' pads sections if needed to ensure they end on a word
  1263. (sixteen bit) boundary.
  1264.  
  1265.    An object file written by `as' has at least three sections, any of
  1266. which may be empty.  These are named "text", "data" and "bss" sections.
  1267.  
  1268.    When it generates COFF output, `as' can also generate whatever other
  1269. named sections you specify using the `.section' directive (*note
  1270. `.section': Section.).  If you do not use any directives that place
  1271. output in the `.text' or `.data' sections, these sections still exist,
  1272. but are empty.
  1273.  
  1274.    When `as' generates SOM or ELF output for the HPPA, `as' can also
  1275. generate whatever other named sections you specify using the `.space'
  1276. and `.subspace' directives.  See `HP9000 Series 800 Assembly Language
  1277. Reference Manual' (HP 92432-90001) for details on the `.space' and
  1278. `.subspace' assembler directives.
  1279.  
  1280.    Additionally, `as' uses different names for the standard text, data,
  1281. and bss sections when generating SOM output.  Program text is placed
  1282. into the `$CODE$' section, data into `$DATA$', and BSS into `$BSS$'.
  1283.  
  1284.    Within the object file, the text section starts at address `0', the
  1285. data section follows, and the bss section follows the data section.
  1286.  
  1287.    When generating either SOM or ELF output files on the HPPA, the text
  1288. section starts at address `0', the data section at address `0x4000000',
  1289. and the bss section follows the data section.
  1290.  
  1291.    To let `ld' know which data changes when the sections are relocated,
  1292. and how to change that data, `as' also writes to the object file
  1293. details of the relocation needed.  To perform relocation `ld' must
  1294. know, each time an address in the object file is mentioned:
  1295.    * Where in the object file is the beginning of this reference to an
  1296.      address?
  1297.  
  1298.    * How long (in bytes) is this reference?
  1299.  
  1300.    * Which section does the address refer to?  What is the numeric
  1301.      value of
  1302.           (ADDRESS) - (START-ADDRESS OF SECTION)?
  1303.  
  1304.    * Is the reference to an address "Program-Counter relative"?
  1305.  
  1306.    In fact, every address `as' ever uses is expressed as
  1307.      (SECTION) + (OFFSET INTO SECTION)
  1308.  
  1309. Further, most expressions `as' computes have this section-relative
  1310. nature.  (For some object formats, such as SOM for the HPPA, some
  1311. expressions are symbol-relative instead.)
  1312.  
  1313.    In this manual we use the notation {SECNAME N} to mean "offset N
  1314. into section SECNAME."
  1315.  
  1316.    Apart from text, data and bss sections you need to know about the
  1317. "absolute" section.  When `ld' mixes partial programs, addresses in the
  1318. absolute section remain unchanged.  For example, address `{absolute 0}'
  1319. is "relocated" to run-time address 0 by `ld'.  Although the linker
  1320. never arranges two partial programs' data sections with overlapping
  1321. addresses after linking, *by definition* their absolute sections must
  1322. overlap.  Address `{absolute 239}' in one part of a program is always
  1323. the same address when the program is running as address `{absolute
  1324. 239}' in any other part of the program.
  1325.  
  1326.    The idea of sections is extended to the "undefined" section.  Any
  1327. address whose section is unknown at assembly time is by definition
  1328. rendered {undefined U}--where U is filled in later.  Since numbers are
  1329. always defined, the only way to generate an undefined address is to
  1330. mention an undefined symbol.  A reference to a named common block would
  1331. be such a symbol: its value is unknown at assembly time so it has
  1332. section *undefined*.
  1333.  
  1334.    By analogy the word *section* is used to describe groups of sections
  1335. in the linked program.  `ld' puts all partial programs' text sections
  1336. in contiguous addresses in the linked program.  It is customary to
  1337. refer to the *text section* of a program, meaning all the addresses of
  1338. all partial programs' text sections.  Likewise for data and bss
  1339. sections.
  1340.  
  1341.    Some sections are manipulated by `ld'; others are invented for use
  1342. of `as' and have no meaning except during assembly.
  1343.  
  1344.